package com.nut.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.Serializable;
import java.util.List;
import java.util.Set;
import com.nut.common.Result;
import com.nut.entity.GoodsInviteLog;
import com.nut.mapper.GoodsInviteLogMapper;
import com.nut.service.GoodsInviteLogService;

@Service
@Slf4j
public class GoodsInviteLogServiceImpl implements GoodsInviteLogService {

    @Autowired
    private GoodsInviteLogMapper goodsInviteLogMapper;

    @Override
    public Result<IPage<GoodsInviteLog>> listPage(Integer pageNo, Integer pageSize) {

        Page<GoodsInviteLog> page = new Page<>(pageNo, pageSize);
        List<GoodsInviteLog> list = goodsInviteLogMapper.listPage(page, 1);
        page.setRecords(list);
        return Result.ok(page);
    }

    @Override
    public Result<IPage<GoodsInviteLog>> selectPage(Integer pageNo, Integer pageSize) {

        Page<GoodsInviteLog> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<GoodsInviteLog> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.orderByDesc(GoodsInviteLog::getId);

        IPage<GoodsInviteLog> list = goodsInviteLogMapper.selectPage(page, queryWrapper);
        return Result.ok(list);
    }

    @Override
    public Result<GoodsInviteLog> getById(Serializable id) {
        GoodsInviteLog goodsInviteLog = goodsInviteLogMapper.selectById(id);
        return Result.ok(goodsInviteLog);
    }

    @Override
    public Result add(GoodsInviteLog goodsInviteLog) {
        goodsInviteLogMapper.insert(goodsInviteLog);
        return Result.ok();
    }

    @Override
    public Result updateById(GoodsInviteLog goodsInviteLog) {
        goodsInviteLogMapper.updateById(goodsInviteLog);
        return Result.ok();
    }

    @Override
    public Result deleteByIds(Set<Integer> ids) {
        for (Integer id : ids) {
            goodsInviteLogMapper.deleteById(id);
        }
        return Result.ok();
    }
}